#!/bin/bash
cd ./build/
mkdir -p ./log
# 1- lib, 2-bench
curpath=`pwd`

do_bench() {
	if [ ! -f "${curpath}/g${1}test_${2}.o" ]; then
		echo "${1}test_${2}.o not exists"
		echo "${2}	${1}	-1" >> ./log/result.tsv
		echo "${2}	${1}	-1" >> ./log/result.tsv
	else
		echo "./${1}test_${2}.o"
		./g${1}test_${2}.o 2> ./log/gtmplog.log
		./cl${1}test_${2}.o 2> ./log/cltmplog.log
		gres=`cat ./log/gtmplog.log`
		clres=`cat ./log/cltmplog.log`
		echo "${2}	${1}	${gres}" >> ./log/result.tsv
		echo "${2}	${1}	${clres}" >> ./log/result.tsv
	fi
	# 确保文件已写入, 防止影响下一次执行
	sleep 1
}

echo "bench	colib	result(us)" > ./log/result.tsv

liblist="aco
coroutine
concurrent
libco
mprompt
cocomi
cocoro"

benchlist="bswitch
generator
breset_exec
ccreate
cswitch
creturn
crelease
ctorture
dnested
dstackuse"
trap "exit" INT
echo "run ${1} times" 
for ((i=1;i<=${1};i++))
do
	for bench in ${benchlist}
	do
		for lib in ${liblist}   
		do
			do_bench ${lib} ${bench}
		done
	done
done